﻿/**********************************弘石项目*******************************************
* 功能描述:考勤统计，考勤汇总，项目概括查询，高级查询，公告管理，资质管理，人力资源管理,电表，消防门
* 作者:刘子奇
* 时间:2021-12-22
* 
**********************************弘石项目*******************************************/
using HongStone.Domain.AttendanceManagement;
using HongStone.Domain.ContractModel;
using HongStone.Domain.SystemSetupModel.InstitutionSettingModel;
using HongStone.Ince;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using MiniExcelLibs;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

namespace HongStone.API.Controllers
{
    [ApiExplorerSettings(GroupName = "Attend")]
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class AttendController : ControllerBase
    {
        private readonly IattInce _ince;
        public AttendController(IattInce ince)
        {
            _ince = ince;
        }
        /// <summary>
        /// 员工信息考勤统计
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetStaffs()
        {
            return Ok(_ince.GetStaffs());
        }
        /// <summary>
        /// 年假统计
        /// </summary>
        /// <returns></returns>
       [HttpGet]
        public IActionResult GetNjtjs()
        {
            return Ok(_ince.GetNjtjs());
        }
        /// <summary>
        /// 出差统计
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetChuchais()
        {
            return Ok(_ince.GetChuchais());
        }
        /// <summary>
        /// 差旅补贴
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult getchailv()
        {
            return Ok(_ince.getchailv());
        }
        /// <summary>
        /// 导出私车公用补贴Excel表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult DownLoad()
        {
            var valuest = _ince.GetChuchais();
            var values = new List<Dictionary<string, string>>();
            foreach (var item in valuest)
            {
                values.Add(new Dictionary<string, string>
                {
                    { "序号",$"{item.ApplyForId}"},{ "姓名",$"{item.ApplyName}"},{ "公里数",$"{item.GongLi}"},{ "日期",$"{item.BeginLeaveTime}"},{ "费用",$"{item.feiyong}"},{ "项目名称",$"{item.EntryName}"}
                });
            }
            var memorystream = new MemoryStream();
            memorystream.SaveAs(values);
            memorystream.Seek(00, SeekOrigin.Begin);
            return new FileStreamResult(memorystream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "私车公用补贴.xlsx"
            };
        }
        /// <summary>
        /// 导出差旅Excel表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult DownLoadchailv()
        {
            var valuest = _ince.getchailv();
            var values = new List<Dictionary<string, string>>();
            foreach (var item in valuest)
            {
                values.Add(new Dictionary<string, string>
                {
                    { "序号",$"{item.ApplyForId}"},{ "姓名",$"{item.ApplyName}"},{ "天数",$"{item.tianshu}"},{ "日期",$"{item.BeginLeaveTime}"},{ "费用",$"{item.feiyong}"},{ "项目名称",$"{item.EntryName}"}
                });
            }
            var memorystream = new MemoryStream();
            memorystream.SaveAs(values);
            memorystream.Seek(00, SeekOrigin.Begin);
            return new FileStreamResult(memorystream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
            {
                FileDownloadName = "差旅补贴.xlsx"
            };
        }
        /// <summary>
        /// 带薪年假
        /// </summary>
        /// <returns></returns>
       [HttpGet]
        public IActionResult GetDaixins()
        {
            return Ok(_ince.GetDaixins());
        }
       [HttpGet]
        public IActionResult GetYuehuizongs()
        {
            return Ok(_ince.GetYuehuizongs());
        }
        /// <summary>
        /// 计算数
        /// </summary>
        /// <returns></returns>
       [HttpGet]
        public IActionResult GetSuanshus()
        {
            return Ok(_ince.GetSuanshus());
        }
        /// <summary>
        /// 年分析
        /// </summary>
        /// <returns></returns>
       [HttpGet]
        public IActionResult nianfenxi()
        {
            return Ok(_ince.nianfenxi());
        }
        /// <summary>
        /// 年汇总
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetNhuizongs()
        {
            return Ok(_ince.GetNhuizongs());
        }
        /// <summary>
        /// 月图表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult yuetubiao()
        {
            return Ok(_ince.yuetubiao());
        }
        /// <summary>
        /// 项目概括
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult Getgaikuo(int pageindex=1, int pagesize=2, string ProjectName="")
        {
            var totalcpunt = 0;
            var list = _ince.Getgaikuo(out totalcpunt, pageindex, pagesize, ProjectName);
            return Ok(new { totalcpunt,list});
        }
        /// <summary>
        /// 日志信息添加
        /// </summary>
        /// <param name="rizhis"></param>
        /// <returns></returns>
      [HttpPost]
        public IActionResult Addrizhi(rizhis rizhis)
        {
            return Ok(_ince.Addrizhi(rizhis));
        }
        // <summary>
        /// 日志信息显示
        /// </summary>
        /// <param name="Title"></param>
        /// <returns></returns>
       [HttpGet]
        public IActionResult GetRizhis(string Title)
        {
            return Ok(_ince.GetRizhis(Title));
        }
        /// <summary>
        /// 日志信息反填
        /// </summary>
        /// <param name="Rid"></param>
        /// <returns></returns>
       [HttpGet]
        public IActionResult GetRizhisBYid(int Rid)
        {
            return Ok(_ince.GetRizhisBYid(Rid));
        }
        /// <summary>
        /// 修改日志信息
        /// </summary>
        /// <param name="rizhis"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult updaterizhi(rizhis rizhis)
        {
            return Ok(_ince.updaterizhi(rizhis));
        }
        /// <summary>
        /// 批量删除日志信息
        /// </summary>
        /// <param name="Rid"></param>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult DelAllrizhi(string Ids)
        {
            return Ok(_ince.DelAllrizhi(Ids));
        }
        /// <summary>
        /// 公告显示
        /// </summary>
        /// <param name="Gtitle"></param>
        /// <returns></returns>
       [HttpGet]
        public IActionResult GetGonggaos(string Gtitle)
        {
            return Ok(_ince.GetGonggaos(Gtitle));
        }
        /// <summary>
        /// 公告添加
        /// </summary>
        /// <param name="gonggaos"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Addgonggao(gonggaos gonggaos)
        {
            return Ok(_ince.Addgonggao(gonggaos));
        }
        /// <summary>
        /// 批量删除公告
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult Delallgonggao(string Ids)
        {
            return Ok(_ince.Delallgonggao(Ids));
        }
        /// <summary>
        /// 高级查询
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetGaojis()
        {
            return Ok(_ince.GetGaojis());
        }
        /// <summary>
        /// 高级查询合同
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetGaojiht()
        {
            return Ok(_ince.GetGaojiht());
        }
        /// <summary>
        /// 资质信息添加
        /// </summary>
        /// <param name="zizhi"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult Addzizhi(zizhi zizhi)
        {
            return Ok(_ince.Addzizhi(zizhi));
        }
        /// <summary>
        /// 资质信息查询显示
        /// </summary>
        /// <param name="Zname"></param>
        /// <param name="jibie"></param>
        /// <param name="YearTime"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetZizhis(string Zname, string jibie, DateTime? YearTime)
        {
            return Ok(_ince.GetZizhis(Zname, jibie, YearTime));
        }
        /// <summary>
        /// 资质批量删除
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
       [HttpGet]
        public IActionResult Delallzizhi(string Ids)
        {
            return Ok(_ince.Delallzizhi(Ids));
        }
        /// <summary>
        /// 查看资质信息
        /// </summary>
        /// <param name="Zid"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetZizhibyid(int Zid)
        {
            return Ok(_ince.GetZizhibyid(Zid));
        }
        /// <summary>
        /// 资质信息修改
        /// </summary>
        /// <param name="zizhi"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult updatezizhi(zizhi zizhi)
        {
            return Ok(_ince.updatezizhi(zizhi));
        }
        /// <summary>
        /// 人力资源管理
        /// </summary>
        /// <returns></returns>
       [HttpGet]
        public IActionResult GetRlzies()
        {
            return Ok(_ince.GetRlzies());
        }
        /// <summary>
        /// 查看员工登录信息
        /// </summary>
        /// <param name="LoginId"></param>
        /// <returns></returns>
      [HttpGet]
        public IActionResult GetLogins(int? LoginId)
        {
            return Ok(_ince.GetLogins(LoginId));
        }
        /// <summary>
        /// 员工基本信息
        /// </summary>
        /// <param name="EmployeeId"></param>
        /// <returns></returns>
       [HttpGet]
        public IActionResult GetEmployees(int? EmployeeId)
        {
            return Ok(_ince.GetEmployees(EmployeeId));
        }
        /// <summary>
        /// 员工教育信息
        /// </summary>
        /// <param name="EducationId"></param>
        /// <returns></returns>
       [HttpGet]
        public IActionResult GetEducations(int? EducationId)
        {
            return Ok(_ince.GetEducations(EducationId));
        }
        /// <summary>
        /// 员工证书情况
        /// </summary>
        /// <param name="CertifivateId"></param>
        /// <returns></returns>
       [HttpGet]
        public IActionResult GetEmployeeCertifivates(int? CertifivateId)
        {
            return Ok(_ince.GetEmployeeCertifivates(CertifivateId));
        }
        // <summary>
        /// 员工工作情况
        /// </summary>
        /// <param name="WorkId"></param>
        /// <returns></returns>
       [HttpGet]
        public IActionResult GetEmployeesWorks(int? WorkId)
        {
            return Ok(_ince.GetEmployeesWorks(WorkId));
        }
        /// <summary>
        /// 员工人力信息
        /// </summary>
        /// <param name="ManpowerId"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetEmployeeManpowers(int? ManpowerId)
        {
            return Ok(_ince.GetEmployeeManpowers(ManpowerId));
        }
        /// <summary>
        /// 电表
        /// </summary>
        /// <param name="dianRequest"></param>
        /// <returns></returns>
       [HttpPost]
        public IActionResult ShowMeteringequipment(DianRequest dianRequest)
        {
            return Ok(_ince.ShowMeteringequipment(dianRequest));
        }
        /// <summary>
        /// 消防门设备列表显示
        /// </summary>
        /// <param name="dianRequest">查询参数</param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult ShowFireexitdoor(DianRequest dianRequest)
        {
            return Ok(_ince.ShowFireexitdoor(dianRequest));
        }
        /// <summary>
        /// 消防门修改状态
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpdateF1State(int id)
        {
            return Ok(_ince.UpdateF1State(id));
        }
    }
}
